package com.molichuxing.gateway.utils;

import java.math.BigDecimal;

import com.molichuxing.gateway.bff.payment.entity.request.create.OrderPayCreateVo;
import com.molichuxing.gateway.contants.PaymentConst;
import com.molichuxing.services.property.PaymentPayWayEnum;
import com.molichuxing.services.property.sdk.WechatpayTradeTypeEnum;

/**
 * 支付工具类
 * 
 * @author zoumingyu
 * @date 2019年10月10日
 *
 */
public class PaymentUtil {

	/**
	 * 订单支付方式转换成用户支付方式
	 * 
	 * @param payWay
	 *            支付方式
	 * @return
	 */
	public static String transUserPayWay(PaymentPayWayEnum payWay) {
		String userPayWay = null;
		if (PaymentConst.WXPAY.contains(payWay)) {
			userPayWay = "微信";
		} else if (PaymentConst.ALPAY.contains(payWay)) {
			userPayWay = "支付宝";
		} else if (PaymentConst.UNIONPAY.contains(payWay)) {
			userPayWay = "银行卡";
		} else if (PaymentConst.POS.contains(payWay)) {
			userPayWay = "银行卡";
		} else if (PaymentConst.OFFLINE.contains(payWay)) {
			userPayWay = "线下支付";
		}
		return userPayWay;
	}

	public static boolean checkAmount(OrderPayCreateVo createVo, BigDecimal payAmount, String testCpu) {
		if (createVo.getPayAmount().compareTo(payAmount) != 0
				&& (testCpu == null || !testCpu.equals(createVo.getCpuSerial()))) {
			return false;
		}
		return true;
	}

	public static WechatpayTradeTypeEnum toWechatpayTradeTypeEnum(PaymentPayWayEnum payWay) {
		WechatpayTradeTypeEnum result = null;
		switch (payWay) {
		case WXPAY_MWEB:
			result = WechatpayTradeTypeEnum.MWEB;
			break;
		case WXPAY_APP:
			result = WechatpayTradeTypeEnum.APP;
			break;
		case WXPAY_JSAPI:
			result = WechatpayTradeTypeEnum.JSAPI;
			break;
		case WXPAY_NATIVE:
			result = WechatpayTradeTypeEnum.NATIVE;
			break;
		case WXPAY_APPLET:
			result = WechatpayTradeTypeEnum.APPLET;
			break;
		default:
			break;
		}
		return result;
	}
}
